<template>
	<el-main class="nopadding">
		<scTable
			ref="table"
			v-bind="list"
			row-key="id"
			stripe
			:hidePropOrder="true"
      tableName="ResourceDetailsList"
			:showSummary="true"
			:summaryMethod="summaryMethod"
      :vritualData="vritualData"
		>
		</scTable>
	</el-main>
</template>

<script setup>
import { column } from "./data.js";
import { reactive } from "vue"
const list = reactive({
  column,
  apiObj: null,
	params: {},
})

const vritualData = reactive([
  {name: "张三", consultNum: 1},
  {name: "张三", consultNum: null},
  {name: "李四", consultNum: 4},
  {name: 3, consultNum: 6},
])

const summaryMethod = function(param) {
	const { columns, data } = param
	const sums = []
	columns.forEach((column, index) => {
		const values = data.map((item) => Number(item[column.property]))
		if(index === 0 ) {
			sums[index] = "一部合计"
			return
		}else{
			if(!values.some(e => Number.isNaN(e))){
					sums[index] = `${values.reduce((prev, curr) => {
    	    const value = Number(curr)
    	    if (!Number.isNaN(value)) {
    	      return prev + curr
    	    } else {
    	      return prev
    	    }
    	  }, 0)}`
    	} else {
    	  sums[index] = 'N/A'
    	}
		}
	})
	return sums

}

</script>

<style scoped lang="scss">
</style>

